import {GET_USER_INFO_REQUEST, GET_USER_INFO_SUCCESS, GET_USER_INFO_FAILURE} from '$actions/userInfo'

const initState = {
    error: '',
    userInfo: {},
    loading: false
}

export default function reducer(state = initState, action){
    switch(action.type){
        case GET_USER_INFO_REQUEST:
        return {
            ...state,
            loading: true,
            userInfo: {},
            error: ''
        }

        case GET_USER_INFO_SUCCESS:
        return {
            ...state,
            loading: false,
            userInfo: action.userInfo,
            error: ''
        }

        case GET_USER_INFO_FAILURE:

        return {
            ...state,
            loading: false,
            error: action.error,
            userInfo: {}
        }

        default:
        return state
    }
}